#include "StdAfx.h"
#include "TwRenderDx.h"
#include "TwTextureDX.h"
#include "TwEngineDx.h"


TwRenderDx::TwRenderDx(void)
:m_uCurSurface(0)
{
	memset(m_pkSurface,0,sizeof(TwRenderSurfaceDx)*MAX_SURFACE);
}

TwRenderDx::~TwRenderDx(void)
{
}

void TwRenderDx::PushSuface(char*pkPath,DWORD dwFVF,BYTE* pkIndex,BYTE* pkVertex,BYTE* pkNormal)
{
	if(pkPath == NULL)
		return;
	GetCurSurface().pkIndexs = pkIndex;
	GetCurSurface().pkVertexs = pkVertex;
	GetCurSurface().pkNormals = pkNormal;
	GetCurSurface().dwFVF = dwFVF;
	GetCurSurface().pkTexture = 0;
	
	++m_uCurSurface;
}
TwRenderSurfaceDx& TwRenderDx::GetCurSurface()
{
	if(m_uCurSurface >= MAX_SURFACE)
		m_uCurSurface = 0;
	return m_pkSurface[m_uCurSurface];
}
void TwRenderDx::RenderSurface()
{
	for (int n = 0; n < MAX_SURFACE; ++n)
	{
		TwTextureDX* pkTex = (TwTextureDX*)m_pkSurface[n].pkTexture;
		if(pkTex == NULL)
			continue;
		GetDevice()->SetRenderState(D3DRS_CULLMODE, 0);
		GetDevice()->SetTexture(0,(LPDIRECT3DTEXTURE9)pkTex->GetData());
		GetDevice()->SetFVF( m_pkSurface[n].dwFVF );
		GetDevice()->DrawIndexedPrimitiveUP(
			D3DPT_TRIANGLELIST,
			0,
			4,
			2,
			(VOID*)m_pkSurface[n].pkIndexs,
			D3DFMT_INDEX16,
			(VOID*)m_pkSurface[n].pkVertexs,
			FVERTEX2D_STRIDE );
	}
}
void TwRenderDx::SortQueue()
{

}
void TwRenderDx::ExcuteRender()
{

}

void TwRenderDx::ResetQueue()
{

}